﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;

public partial class Controls_CategoryMeau : System.Web.UI.UserControl
{
    BLL.SHANGPIN shangpin = new BLL.SHANGPIN();
    DataTable dt;
    StringBuilder Sb;
    protected void Page_Load(object sender, EventArgs e)
    {
        Url = BLL.Common.ApplicationPath + "/Product/Cagegory_Num.html";
        Sb = new StringBuilder();
        dst();
        Meau = BindTree();
    }
    public string _url;
    public string _meau;
    #region meau导航url
    public string Url
    {
        get { return _url; }
        set { _url = value; }
    }
    #endregion

    #region 生成Meau
    public string Meau
    {
        get { return _meau; }
        set { _meau = value; }
    }
    #endregion

    #region 创建数据源

    private void dst()
    {
        DataSet ds = shangpin.GetSPCOMMODITY_TYPEList_Order(0);
        if (ds != null)
        {
            dt = ds.Tables[0];
            dt.TableName = "Category";
        }
    }
    #endregion

    #region 生成导航树
    private string BindTree()
    {
        Sb.Append("<li class=\"r_cl\">");
        Sb.Append("<a href=\""+BLL.Common.ApplicationPath+"/Product/AllProduct.aspx\" >全部商品</a>");
        Sb.Append("</li>");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (dt.Rows[i]["CT_Name"].ToString().IndexOf('-') > -1)
            {
                Sb.Append("<li class=\"r_clx\">");
            }
            else
            {
                Sb.Append("<li class=\"r_cl\">");
            }
            Sb.Append( GetBlank(dt.Rows[i]["CT_Name"].ToString()) + "<a href=\"" + Url.Replace("Num", dt.Rows[i]["CT_CODE"].ToString()) + "\">" + dt.Rows[i]["CT_Name"].ToString().Replace("--", "") + "</a></li>");
        }
        return Sb.ToString();
    }
    #endregion
    private string GetBlank(string str)
    {
        string result = "";
        int index = str.LastIndexOf('-');
        if (index > -1)
        {
            string temp = str.Substring(0, index+1);
            for (int i = 0; i < temp.Length; i++)
            {
                result += "&nbsp;";
            }
        }
        return result;
    }
}
